package com.lcxw.hxzbapi.scheduleTask;

import com.lcxw.hxzbapi.controller.roomcontroller.RoomRealization;
import com.lcxw.hxzbapi.service.YwpdRoomService;
import com.lcxw.hxzbcommon.common.RedisUtils;
import com.lcxw.hxzbcommon.common.RoomUtils;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class DealRoomFireScheduled {

    @Resource
    YwpdRoomService ywpdRoomService;

    @Resource
    RedisUtils redisUtils;

    @Resource
    RoomRealization roomRealization;

    /**
     *每日0点，开始清理房间的火力值，如果房间在播，则发送IM消息通知火力值变更
     */
//    @Scheduled(cron = "0 * * * * ?")
    @Scheduled(cron = "0 0 0 * * ?")
    void dealRoomFireScheduled(){
        List<Long> roomIdList = ywpdRoomService.selectAllRoomId();
        for (Long roomId:roomIdList) {
            String fire_redisKey = RoomUtils.get_fire_redisKey(roomId);
            if (redisUtils.hasKey(fire_redisKey)){
                redisUtils.string_delete(fire_redisKey);
                if (ywpdRoomService.selectRoomByRoomId(roomId).getLiveStatus() == 1){
                    roomRealization.fireChange(roomId);
                }
            }
        }
    }
}
